using System;
using System.Web;
using System.Web.UI;

namespace WroxControls 
{
   public class MyFirstControl : Control,
											IPostBackEventHandler
   {

		public int Number
		{
			get
			{
				if ( ViewState["Number"] != null )
					return (int) ViewState["Number"];

				return 50;
			}

			set
			{
				ViewState["Number"] = value;
			}
		}

		public void RaisePostBackEvent(string eventArgument)
		{
			if ( eventArgument == "inc" )
				Number = Number + 1;

			if ( eventArgument == "dec" )
				Number = Number - 1;

		}
      protected override void Render(HtmlTextWriter writer) 
      { 
			writer.Write("The Number is " + Number.ToString() + " (" );
			
			writer.Write("<a href=\"javascript:" + 
				Page.GetPostBackEventReference(this,"inc") + 
				"\"'>Increase Number</a>");

			writer.Write(" or " );
		
         writer.Write("<a href=\"javascript:" + 
				Page.GetPostBackEventReference(this,"dec") + 
				"\">Decrease Number)</a>");
      }
   }
};
